<template>
	<view class="user-button">
		<button class="button" @click="lookUserInfo()">用户列表信息查看</button>
		<button class="button" @click="downUserInfo()">用户信息下载</button>
	</view>
</template>

<script>
	export default {
		data() {
			return {

			}
		},
		methods: {
			lookUserInfo() {
				uni.navigateTo({
					url: '../pageinfo/pageinfo'
				})
			},
			downUserInfo() {
				// uni.request({
				// 	url: 'http://localhost:9090/register/exportUserWithExcel',
				// 	method: 'GET',
				// 	success: function(res) {
				// 		console.log(res);
				// 	}
				// })
				const that = this;
				uni.downloadFile({
					url: 'register/exportUserWithExcel',
					success: (res) => {
						console.log(res);
						that.saveImg(res.tempFilePath)
					}
				})
			},
			saveImg: function(url){
				var oA = document.createElement("a");
				oA.download = '用户注册信息表.xls';// 设置下载的文件名，默认是'下载'
				oA.href = url;
				document.body.appendChild(oA);
				oA.click();
				oA.remove(); // 下载之后把创建的元素删除
			},
		}
	}
</script>

<style>
	.user-button {
		text-align: center;
		margin-top: 150px;
	}

	.button {
		margin-top: 30px;
		width: 180px;
		height: 40px;
	}
</style>
